var param = new Object({
	init : function() {
		this.timeSize = ''
		this.queryDate = ''
		this.compareDate = ''
		this.netYuan = ''
		this.dimension = ''
		this.tai = ''
		this.city_code = ''
		this.cell_id = ''
		this.enodeb_id = ''
		this.usergroup = ''
		this.msisdn = ''
		this.terminal_brand = ''
		this.terminal_model = ''
		this.apn = ''
		this.tai_check = ''
		this.	enodebid_check = ''
		this.	cell_id_check = ''
	},
	setDimensionParam : function(dimension) {
		switch (dimension) {
		case 'area':
			this.city_code = $('#area').val()
			if ($('#tai_check').is(':checked')) {
				this.tai_check = 1
				this.tai = $('#tai').val()
			}
			if ($('#enodebid_check').is(':checked')) {
				this.	enodebid_check = 1
				this.enodeb_id = $('#enodeb_id').val()
			}
			if ($('#cell_id_check').is(':checked')) {
				this.	cell_id_check = 1
				this.cell_id = $('#cell_id').val()
			}
			break
		case 'usergroup':
			this.usergroup = $('#groupId').val()
			break
		case 'user':
			this.msisdn = $('#userId').val()
			break
		case 'terminal_type':
			this.terminal_brand = $('#terminalBrandId').val()
			this.terminal_model = $('#terminalModelId').val()
			break
		case 'apn':
			this.apn = $('#apnId').val()
			break
		default:
			this.dimension = '';	
		}
	},
	setParam : function() {
		this.init()
		this.timeSize = $('input:radio[name="timeSize"]:checked').val();
		this.queryDate = $('#queryDate').val()
		this.compareDate = $('#compareDate').val()
		this.netYuan = $('#netYuan').val()
		this.dimension = $('input:radio[name="dimension"]:checked').val();
		this.setDimensionParam(this.dimension)
	}
});
var attaChar;
var s1Char;
var tauChar;
var sessionChar;
var pdnChar;
var eHRPDChar;
var d;
$(function() {
	showArearList("area");
	$("#groupId").combobox({
		width : 40
	});
	$("#terminalBrandId").combobox({
		select : function(event, ui) {
			loadTerminalModel();
		},
		width : 100
	});
	$("#terminalModelId").combobox({
		width : 100
	});
	$("#apnId").combobox({
		width : 40
	});
	$("#sgw").combobox({
		width : 40
	});
	// 图表
	attaChar = echarts.init(document.getElementById('attaChar'));
	attaChar.on('click', function(param) {
		attaLinkTo(param.seriesName,param.name)
	})
	s1Char = echarts.init(document.getElementById('s1Char'));
	s1Char.on('click', function(param) {
		s1LinkTo(param.seriesName,param.name)
	})
	tauChar = echarts.init(document.getElementById('tauChar'));
	tauChar.on('click', function(param) {
		tauLinkTo(param.seriesName,param.name)
	})
	sessionChar = echarts.init(document.getElementById('sessionChar'));
	sessionChar.on('click', function(param) {
		sessionLinkTo(param.seriesName,param.name)
	})
	pdnChar = echarts.init(document.getElementById('pdnChar'));
	pdnChar.on('click', function(param) {
		pdnLinkTo(param.seriesName,param.name)
	})
	eHRPDChar = echarts.init(document.getElementById('eHRPDChar'));
	eHRPDChar.on('click', function(param) {
		eHRPDLinkTo(param.seriesName,param.name)
	})
//	getList();
})

function attaLinkTo(name,eCharsTime) {
	var p ="flag=1&timeSize=" + param.timeSize + "&sgw=" + param.netYuan + "&tac="
			+ param.tai + "&cityCode=" + param.city_code + "&areaHouse="
			+ param.cell_id + "&eNodeBID=" + param.enodeb_id + "&groupId="
			+ param.usergroup + "&userId=" + param.msisdn + "&terminalBrandId="
			+ param.terminal_brand + "&terminalModelId=" + param.terminal_model
			+ "&apn=" + param.apn  + "&tac_check=" + param.tai_check +"&enodebid_check=" +  param.enodebid_check + "&cell_id_check=" + param.cell_id_check
	switch (this.dimension) {
	case "area":
		p += "&selectRadio=4"
		break;
	case "user":
		p += "&selectRadio=1"
		break;
	// case "apn":
	// param="&selectRadio="
	// break;
	case "usergroup":
		p += "&selectRadio=0"
		break;
	case "terminal_type":
		p += "&selectRadio=2"
		break;
	}
	if(name.startWith('查询')){
		p += "&queryDate=" + param.queryDate
	}
	if(name.startWith('对比')){
		p += "&queryDate=" + param.compareDate
	}
	p += "&eCharsTime="+eCharsTime+"&jspType=kpi_analysis"
	url = "/businessAnalysis/attachment/index?" + p;
	title = "附着质量分析"
	linkTab(title, url)
}

function tauLinkTo(name,eCharsTime) {
	var p = "timeSize=" + param.timeSize + "&sgw=" + param.netYuan + "&tac="
			+ param.tai + "&cityCode=" + param.city_code + "&areaHouse="
			+ param.cell_id + "&eNodeBID=" + param.enodeb_id + "&groupId="
			+ param.usergroup + "&userId=" + param.msisdn + "&terminalBrandId="
			+ param.terminal_brand + "&terminalModelId=" + param.terminal_model
			+ "&apn=" + param.apn  + "&tac_check=" + param.tai_check +"&enodebid_check=" +  param.enodebid_check + "&cell_id_check=" + param.cell_id_check
	switch (this.dimension) {
	case "area":
		p += "&selectRadio=4"
		break;
	case "user":
		p += "&selectRadio=1"
		break;
	// case "apn":
	// param="&selectRadio="
	// break;
	case "usergroup":
		p += "&selectRadio=0"
		break;
	case "terminal_type":
		p += "&selectRadio=2"
		break;
	}
	if(name.startWith('查询')){
		p += "&queryDate=" + param.queryDate
	}
	if(name.startWith('对比')){
		p += "&queryDate=" + param.compareDate
	}
	p += "&eCharsTime="+eCharsTime+"&jspType=kpi_analysis"
	url = "/businessAnalysis/tui/index?" + p;
	title = "TAU分析"
	linkTab(title, url)
}

function sessionLinkTo(name,eCharsTime) {
	var p = "timeSize=" + param.timeSize + "&netYuan=" + param.netYuan + "&tai="
	+ param.tai + "&city_code=" + param.city_code + "&cell_id="
	+ param.cell_id + "&enodeb_id=" + param.enodeb_id + "&usergroup="
	+ param.usergroup + "&msisdn=" + param.msisdn + "&terminal_brand="
	+ param.terminal_brand + "&terminal_model=" + param.terminal_model
	+ "&apn=" + param.apn + "&dimension=" + param.dimension  + "&tac_check=" + param.tai_check +"&enodebid_check=" +  param.enodebid_check + "&cell_id_check=" + param.cell_id_check
	if(name.startWith('查询')){
		p += "&queryDate=" + param.queryDate
	}
	if(name.startWith('对比')){
		p += "&queryDate=" + param.compareDate
	}
	p += "&eCharsTime="+eCharsTime+"&jspType=kpi_analysis"
	url = "/businessAnalysis/session/sessioncreateanalysis?" + p;
	title = "会话创建"
	linkTab(title, url)
}

function s1LinkTo(name,eCharsTime) {
	var p = "timeSize=" + param.timeSize + "&sgw=" + param.netYuan + "&tac="
	+ param.tai + "&cityCode=" + param.city_code + "&areaHouse="
	+ param.cell_id + "&eNodeBID=" + param.enodeb_id + "&groupId="
	+ param.usergroup + "&userId=" + param.msisdn + "&terminalBrandId="
	+ param.terminal_brand + "&terminalModelId=" + param.terminal_model
	+ "&apn=" + param.apn  + "&tac_check=" + param.tai_check +"&enodebid_check=" +  param.enodebid_check + "&cell_id_check=" + param.cell_id_check
	switch (this.dimension) {
	case "area":
	p += "&selectRadio=4"
	break;
	case "user":
	p += "&selectRadio=1"
	break;
	// case "apn":
	// param="&selectRadio="
	// break;
	case "usergroup":
	p += "&selectRadio=0"
	break;
	case "terminal_type":
	p += "&selectRadio=2"
	break;
	}
	if(name.startWith('查询')){
		p += "&queryDate=" + param.queryDate
	}
	if(name.startWith('对比')){
		p += "&queryDate=" + param.compareDate
	}
	p += "&eCharsTime="+eCharsTime+"&jspType=kpi_analysis"
	url = "/businessAnalysis/switchpa/index?" + p;
	title = "切换性能分析"
	linkTab(title, url)
}

function pdnLinkTo(name,eCharsTime) {
	var p = "timeSize=" + param.timeSize + "&netYuan=" + param.netYuan + "&tai="
	+ param.tai + "&city_code=" + param.city_code + "&cell_id="
	+ param.cell_id + "&enodeb_id=" + param.enodeb_id + "&usergroup="
	+ param.usergroup + "&msisdn=" + param.msisdn + "&terminal_brand="
	+ param.terminal_brand + "&terminal_model=" + param.terminal_model
	+ "&apn=" + param.apn + "&dimension=" + param.dimension  + "&tac_check=" + param.tai_check +"&enodebid_check=" +  param.enodebid_check + "&cell_id_check=" + param.cell_id_check
	if(name.startWith('查询')){
		p += "&queryDate=" + param.queryDate
	}
	if(name.startWith('对比')){
		p += "&queryDate=" + param.compareDate
	}
	p += "&eCharsTime="+eCharsTime+"&jspType=kpi_analysis"
	url = "/businessAnalysis/pdn/pdnconnectanalysis?" + p
	title = "PDN链接分析";
	linkTab(title, url)
}

function eHRPDLinkTo(name,eCharsTime) {
	var p = "timeSize=" + param.timeSize + "&sgw=" + param.netYuan + "&tac="
	+ param.tai + "&cityCode=" + param.city_code + "&areaHouse="
	+ param.cell_id + "&eNodeBID=" + param.enodeb_id + "&groupId="
	+ param.usergroup + "&userId=" + param.msisdn + "&terminalBrandId="
	+ param.terminal_brand + "&terminalModelId=" + param.terminal_model
	+ "&apn=" + param.apn  + "&tac_check=" + param.tai_check +"&enodebid_check=" +  param.enodebid_check + "&cell_id_check=" + param.cell_id_check
	switch (this.dimension) {
	case "area":
	p += "&selectRadio=4"
	break;
	case "user":
	p += "&selectRadio=1"
	break;
	// case "apn":
	// param="&selectRadio="
	// break;
	case "usergroup":
	p += "&selectRadio=0"
	break;
	case "terminal_type":
	p += "&selectRadio=2"
	break;
	}
	if(name.startWith('查询')){
		p += "&queryDate=" + param.queryDate
	}
	if(name.startWith('对比')){
		p += "&queryDate=" + param.compareDate
	}
	p += "&eCharsTime="+eCharsTime+"&jspType=kpi_analysis"
	url = "/businessAnalysis/eHRPD/index?" + p;
	title = "eHRPD过程性能分析"
	linkTab(title, url)
}

function getList() {
	param.setParam()
	console.log(param)
	initChar("attaChar", attaChar)
	initChar("s1Char", s1Char)
	initChar("tauChar", tauChar)
	initChar("sessionChar", sessionChar)
	initChar("pdnChar", pdnChar)
	initChar("eHRPDChar", eHRPDChar)
}

function handleDimension() {
	var a = $("input[name='dimension']:checked");
	if (a.val() == 'area') {
		$("#enodebid_check").attr("disabled", false);
		$("#tai_check").attr("disabled", false);
		$("#cell_id_check").attr("disabled", false);
		$("#enodeb_id").attr("readonly", false);
		$("#tai").attr("readonly", false);
		$("#cell_id").attr("readonly", false);
	} else {
		$("#enodebid_check").attr("disabled", true);
		$("#tai_check").attr("disabled", true);
		$("#cell_id_check").attr("disabled", true);
		$("#enodeb_id").attr("readonly", true);
		$("#tai").attr("readonly", true);
		$("#cell_id").attr("readonly", true);
	}
}

function initChar(table_type, Char) {
	// 查询
	Char.clear();
	Char.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../../businessSense/kPIAnalysis/getKpiAnalysisChart?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"timeSize" : param.timeSize,
			"queryDate" : param.queryDate,
			"compareDate" : param.compareDate,
			"netYuan" : param.netYuan,
			"dimension" : param.dimension,
			"city_code" : param.city_code,
			"tai" : param.tai,
			"cell_id" : param.cell_id,
			"enodeb_id" : param.enodeb_id,
			"usergroup" : param.groupId,
			"msisdn" : param.msisdn,
			"terminal_brand" : param.terminal_brand,
			"terminal_model" : param.terminal_model,
			"apn" : param.apn,
			"table_type" : table_type,
			"tai_check":param.tai_check,
			"enodebid_check":param.enodebid_check,
			"cell_id_check":param.cell_id_check
		},
		success : function(data) {
			Char.setOption(data, true);
			Char.hideLoading();
		}
	});
}

// 下拉树 begin
function onClick(e, treeId, treeNode) {
	var zTree = $.fn.zTree.getZTreeObj("treeDemo"), nodes = zTree
			.getSelectedNodes(), v = "";
	nodes.sort(function compare(a, b) {
		return a.id - b.id;
	});
	for (var i = 0, l = nodes.length; i < l; i++) {
		v += nodes[i].name + ",";
	}
	if (v.length > 0)
		v = v.substring(0, v.length - 1);
	var cityObj = $("#citySel");
	cityObj.attr("value", v);
	$("#area").val(treeNode.id);

	hideMenu();
}
/**
 * 显示树
 */
function showMenu() {
	var cityObj = $("#citySel");
	var cityOffset = $("#citySel").offset();
	$("#menuContent").css({
		left : cityOffset.left - 26 + "px",
		top : cityOffset.top - 206 + "px"
	}).slideDown("fast");

	$("body").bind("mousedown", onBodyDown);
}
/**
 * 隐藏树
 */
function hideMenu() {
	$("#menuContent").fadeOut("fast");
	$("body").unbind("mousedown", onBodyDown);
}

/**
 * 根据终端类型，加载终端型号
 * 
 * @param parentid
 */
function loadTerminalModel() {
	var terminalBrand = $("#terminalBrandId").val();

	$
			.ajax({
				url : '../../feature/terminalUE/terminalModelInfos?terminalBrand='
						+ terminalBrand,
				type : 'POST',
				dataType : 'JSON',
				error : function() {
					alert('Error loading data!');
				},
				success : function(msg) {
					$("#terminalModelId").remove();
					$("#terminalModelTD")
							.append(
									$("<select id='terminalModelId' name='terminalModelId'></select>"));
					$("#terminalModelId").combobox();
					var list = msg.terminalModelList;
					$.each(eval(list), function(i, item) {
						$(
								"<option value='" + item.terminal_model + "'>"
										+ item.terminal_model + "</option>")
								.appendTo($("#terminalModelId"));
					});
				}
			});

}

function onBodyDown(event) {
	if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(
			event.target).parents("#menuContent").length > 0)) {
		hideMenu();
	}
}

function resetQueryForm() {
	$('#queryForm')[0].reset();
}
function forwordInterfaceFailure(dateType, paramDate) {
	var url = "/kpi/interfaceFailure/index?dateType=" + dateType
			+ "&paramDate=" + paramDate + "&interfaceType=2&signalType=1";
	linkTab("接口故障", url)
}

function clearDate() {
	$("#queryDate").val("")
	$("#compareDate").val("")
}

String.prototype.startWith = function(str) {
	if (str == null || str == "" || this.length == 0 || str.length > this.length)
		return false;
	if (this.substr(0, str.length) == str)
		return true;
	else
		return false;
	return true;
}  
